package servlet;

//import dao.UserDAO;

import dao.UserDAO;
import entity.User;
//import dao.daoTest;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.List;


import lombok.SneakyThrows;
import serviceImpl.register;

@WebServlet(name = "RegisterServlet", value = "/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");


        String account = request.getParameter("account");
        String password = request.getParameter("password");
        System.out.println("account:" + account + ",password:" + password);
//        daoTest dao=new daoTest();
//
//        List<User> test = dao.test();
//        for(User u:test){
//            System.out.println(u);
//        }


        register register = new register();
        int t = register.register(account, password);
        if(t!=0){
            String text="您的用户名为：\n"+account+"\n您的密码为: \n"+password;
            System.out.println(text);
            PrintWriter printWriter=response.getWriter();
            printWriter.print(text);
        }

    }
}
